Skip to content

add BigIntegerConverter#308

Open
arnzel wants to merge 4 commits into
aaberg:masterfrom
arnzel:master
Open

add BigIntegerConverter#308
arnzel wants to merge 4 commits into
aaberg:masterfrom
arnzel:master

Conversation

@arnzel

@arnzel arnzel commented Nov 16, 2018

Copy link
Copy Markdown

Add Converter for BigInteger

@zapodot

zapodot commented Nov 20, 2018

Copy link
Copy Markdown
Collaborator

@arnzel Thank you for your contribution. As we try to improve our test coverage we require all PR-s to include tests. Can you please add some and update this PR?

@arnzel

arnzel commented Nov 20, 2018

Copy link
Copy Markdown
Author

yes sure

@arnzel

arnzel commented Nov 21, 2018

Copy link
Copy Markdown
Author

@zapodot : i added some tests and library assertJ for better failing errors

@zapodot

zapodot commented Nov 21, 2018

Copy link
Copy Markdown
Collaborator

@arnzel I see from your commit that you have added a dependency on AssertJ. Any chance you could use the basic JUnit assertions instead? Thanks again for you contribution 👍


import java.math.BigInteger;

public class BigIntegerConverterTest {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test where you try to convert a null value?

@arnzel

arnzel commented Nov 21, 2018

Copy link
Copy Markdown
Author

@arnzel I see from your commit that you have added a dependency on AssertJ. Any chance you could use the basic JUnit assertions instead? Thanks again for you contribution

well i can do it,but i dont like JUNIt Assertions like "assertEquals" and "assertTrue". they only tell you somethig like "expected true but was false".AssertJ gives you much more information and is better maintained like other matching libraries like hamcrest

@zapodot

zapodot commented Nov 21, 2018 via email

Copy link
Copy Markdown
Collaborator

@arnzel

arnzel commented Nov 22, 2018

Copy link
Copy Markdown
Author

@zapodot okay i removed assertJ and use hamcrest matchers. also i added converting null values

@arnzel

arnzel commented Nov 22, 2018

Copy link
Copy Markdown
Author

@zapodot : i dont understand travic ci test error, is it related to my change ?

@zapodot

zapodot commented Nov 23, 2018

Copy link
Copy Markdown
Collaborator

@arnzel we are experiencing some weird behaviour in our builds right now. Will await merge before until we have a green master branch. Good job!

@nryanov nryanov left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that in cases when we want to get BigInteger instance from Number or String we need to use number.longValue() or Long.parseLong(str) to save precision, otherwise, if number exceeds the MAX_INT then after conversion we'll lose initial value

Thank you for your work!

return (BigInteger)number;
}
else{
return BigInteger.valueOf(number.intValue());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is seems that number.longValue() would be better than number.intValue(). Otherwise you can lost precision.
Also, it's more native to use long than int when you want to get BigInteger

@Override
protected BigInteger convertStringValue(String string) {
if(null != string) {
return BigInteger.valueOf(Integer.parseInt(string));

@nryanov nryanov Jan 17, 2019

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Long.parseLong(...) would be better or, maybe, there is another even better option?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants